package org.huangrui.juc.source.atomic;

import java.util.HashMap;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.LongBinaryOperator;

/**
 * @Author hr
 * @Create 2024-04-08 12:31
 */
public class T06_LongAdderAPI {
    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();
        longAdder.increment();
        longAdder.increment();
        longAdder.increment();

        System.out.println(longAdder.sum());
        LongAccumulator longAccumulator = new LongAccumulator(new LongBinaryOperator() {
            @Override
            public long applyAsLong(long left, long right) {
                return left+right;
            }
        },0);

        longAccumulator.accumulate(3);
        longAccumulator.accumulate(4);
        System.out.println(longAccumulator.get());
        // new HashMap<>().put()
    }
}
